package com.hirsi.common.core.validator;

import cn.hutool.core.lang.Validator;
import com.hirsi.common.core.constant.CommonConstant;
import com.hirsi.common.core.validator.annotation.PhoneCode;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * 手机验证码实现
 * @author 封夕
 * @since 2023/6/7 17:28
 */
public class PhoneCodeValidator implements ConstraintValidator<PhoneCode, String> {
    @Override
    public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
        return Validator.isNumber(s) && s.length() == CommonConstant.PHONE_CODE_LENGTH;
    }
}
